<%@ tag language="java" pageEncoding="UTF-8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>

<%@ attribute name="_formId" required="true" type="java.lang.String" %>

<c:set var="start" value="${page.number*page.size+1}"/>
<c:set var="pageNo" value="${page.number+1}"/>
<c:if test="${page.totalElements>0}">
    <div class="row">
        <div class="col-xs-3" >
            <div class="tables-info" id="sample-table-2_info">
                当前第${start}<c:if test="${page.numberOfElements gt 1}">-${start+(page.numberOfElements-1)}</c:if>条 共${page.totalPages}页,${page.totalElements}条
            </div>
        </div>
        <div class="col-xs-9">
            <div class="tables-paginate paging_bootstrap">
                <ul class="pagination  pull-right">
                    <c:if test="${page.totalPages gt 1  and pageNo  gt 1}">
                        <li class="prev"><a href="javascript:void(0)" onclick='setPageNo(1);'><i class="fa fa-angle-double-left"></i></a></li>
                        <li class="prev"><a href="javascript:void(0)" onclick='setPageNo(${pageNo-1});'><i
                                class="fa fa-angle-left"></i></a></li>
                    </c:if>

                    <c:choose>
                        <c:when test="${page.totalPages  eq  0}"></c:when>
                        <c:when test="${page.totalPages  eq  1}">
                            <li class="active"><a href="javascript:void(0)" >${pageNo}</a></li>
                        </c:when>
                        <c:when test="${page.totalPages  eq  2}">
                            <li class="${(pageNo  ==  1) ? 'active' : '' }"><a href="javascript:void(0)"  onclick='setPageNo(1);'>1</a></li>
                            <li class="${(pageNo  ==  2) ? 'active' : '' }"><a href="javascript:void(0)" onclick='setPageNo(2);'>2</a></li>
                        </c:when>


                        <c:otherwise>
                            <c:choose>
                                <c:when test="${ pageNo eq 1}">
                                    <li class="active"><a href="javascript:void(0)">${pageNo}</a></li>
                                    <li><a href="javascript:void(0)" onclick='setPageNo(${pageNo+1});'>${pageNo+1}</a></li>
                                    <li><a href="javascript:void(0)" onclick='setPageNo(${pageNo+2});'>${pageNo+2}</a></li>
                                </c:when>
                                <c:when test="${pageNo gt 1 and pageNo lt page.totalPages}">
                                    <li class="${(pageNo  eq  1) ? 'active' : '' }"><a href="javascript:void(0)" onclick='setPageNo(${pageNo-1});'>${pageNo-1}</a></li>
                                    <li class= "${(pageNo  !=  1 and  pageNo !=page.totalPages) ? 'active' : '' }" onclick='setPageNo(${pageNo});'><a href="javascript:void(0)">${pageNo}</a></li>
                                    <li class="${(pageNo  eq   page.totalPages) ? 'active' : ''}"><a href="javascript:void(0)" onclick='setPageNo(${pageNo+1});'>${pageNo+1}</a></li>
                                </c:when>
                                <c:when test="${pageNo eq page.totalPages}">
                                    <li><a href="javascript:void(0)" onclick='setPageNo(${pageNo-2});'>${pageNo-2}</a></li>
                                    <li><a href="javascript:void(0)" onclick='setPageNo(${pageNo-1});'>${pageNo-1}</a></li>
                                    <li class="active"><a href="javascript:void(0)">${pageNo}</a></li>
                                </c:when>
                            </c:choose>

                        </c:otherwise>
                    </c:choose>

                    <c:if test="${page.totalPages gt 1 and  pageNo lt page.totalPages}">
                        <li class="next"><a href="javascript:void(0)" onclick='setPageNo(${pageNo+1});'><i
                                class="fa fa-angle-right"></i></a></li>
                        <li class="next"><a href="javascript:void(0)" onclick='setPageNo(${page.totalPages});' ><i class="fa fa-angle-double-right"></i></a></li>
                    </c:if>
                    <c:if test="${page.totalPages gt 0}">
                        &nbsp; 到第 <input type="text" id="page_No" class="goto-page-input" value="${pageNo}"
                                         onkeyup="this.value=this.value.replace(/\D/g,'')" onafterpaste="this.value=this.value.replace(/\D/g,'')"
                                         size="3" maxlength="10"/> 页 <input type="button" id="btn_goto_page" class="btn btn-xs btn-primary" value="跳 转"/>
                    </c:if>

                </ul>

            </div>
        </div>
        <script type="text/javascript">
            function setPageNo(pageNo) {
                $("#page_No").val(pageNo);
                $("#btn_goto_page").click();
            }
            $(document).ready(function () {
                $("#btn_goto_page").on("click", function (e) {
                    e.preventDefault();
                    if($("#page_No").val()*1>${page.totalPages}){
                        return;
                    }
                    $("#${pageScope._formId}").find("input[name='pageIndex']").val($("#page_No").val());
                    $("#${pageScope._formId}").submit();
                });
            });
        </script>
    </div>
</c:if>

